package com.sky.service.impl;

import com.sky.constant.MessageConstant;
import com.sky.result.Result;
import com.sky.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;


@Service
public class ShopServiceImpl implements ShopService {
    private String keyStatus="keyStatus";
    @Autowired
    StringRedisTemplate redisTemplate;
    @Override
    public Result<Integer> getStatus() {
        String status = redisTemplate.opsForValue().get(keyStatus);
        if (status==null){
            return Result.success(null);
        }
        return Result.success(Integer.parseInt(status));
    }

    public Result setStatus(Integer status){
        if (status ==null){
            return Result.error(MessageConstant.UNKNOWN_ERROR);
        }
        redisTemplate.opsForValue().set(keyStatus,String.valueOf(status));
        return Result.success();
    }


}
